package com.hsc.account;

import java.util.List;
import java.util.Map;

import android.content.Context;
import android.graphics.Color;
import android.text.format.Time;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;

public class gridadapter2 extends BaseAdapter {

	private LayoutInflater layoutInflater;
	private List<Map<String, Object>> data_list=null;
	private String use;

	public gridadapter2(Context context,List<Map<String, Object>> data_list,String use)
	{
		this.data_list = data_list;
		layoutInflater = LayoutInflater.from(context);
		this.use = use;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return data_list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return data_list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View view = null;

		if (layoutInflater != null) {

			view = layoutInflater.inflate(R.layout.typeitem, null);
			LinearLayout line =  (LinearLayout) view.findViewById(R.id.mline);
			TextView type = (TextView) view.findViewById(R.id.type);
			TextView type1 = (TextView) view.findViewById(R.id.type1);
			TextView type2 = (TextView) view.findViewById(R.id.type2);
			TextView type3 = (TextView) view.findViewById(R.id.type3);

			TextView tsum = (TextView) view.findViewById(R.id.tsum);
			if(data_list.size()>0)
			{
				String typev = data_list.get(position).get("type").toString();

				//获取自定义的类实例
				if(typev.length()<=1)
				{
					type.setText(typev);
				}else if(typev.length()<=2)
				{
					type.setText(typev.substring(0,1));
					type1.setText(typev.substring(1, typev.length()));
				}else if(typev.length()<=3)
				{
					type.setText(typev.substring(0,1));
					type1.setText(typev.substring(1, 2));
					type2.setText(typev.substring(2, typev.length()));
				}
				else if(typev.length()<=4)
				{
					type.setText(typev.substring(0,1));
					type1.setText(typev.substring(1, 2));
					type2.setText(typev.substring(2, 3));
					type3.setText(typev.substring(3, typev.length()));
				}

				if(typev.equals(use))
				{
					line.setBackgroundColor(Color.GRAY);
					twoActivity.gv=position;
				}else
				{
					line.setBackgroundColor(Color.WHITE);
				}

				tsum.setText(data_list.get(position).get("tsum").toString());
			}



		}
		return view;
	}

}
